﻿using System.Collections.Generic;
using Core.Domain;

namespace Core.SyntaxAnalysis.Classes
{
    public abstract class SubProgram
    {
        public Block Body;
        public Identificator Name;
        public Declrs Variables;
        public Declrs Arguments;

        protected SubProgram(Identificator name, Declrs arguments, Declrs variables, Block body)
        {
            Body = body;
            Name = name;
            Arguments = arguments;
            Variables = variables;
        }

        virtual public bool SemanticCheck(ref List<CompilerError> errors)
        {
            if (Name == null)
            {
                return false;
            }
            if (Variables != null && !Variables.SemanticCheck(ref errors))
            {
                return false;
            }
            if (Arguments != null && !Arguments.SemanticCheck(ref errors))
            {
                return false;
            }
            if (Body != null && !Body.SemanticCheck(ref errors))
            {
                return false;
            }
            return true;
        }
    }
}
